package com.example.bbgds.test;

import android.content.Context;
import android.util.AttributeSet;
import android.util.Log;
import android.view.MotionEvent;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.RelativeLayout;
import android.widget.ListView;
import android.widget.TextView;

/**
 * Created by bbgds on 2016/3/1.
 */
public class View2 extends RelativeLayout{
    private ListView mListView;

    public View2(Context context) {
        this(context, null);
    }

    public View2(Context context, AttributeSet attrs) {
        this(context, attrs, 0);
    }

    public View2(Context context, AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
        this.setBackgroundColor(0xFFFFFFFF);
        View.inflate(context, R.layout.layout2, this);
        mListView = (ListView)findViewById(R.id.listview);
        mListView.setAdapter(new MyAdapter());
    }

    @Override
    public boolean onTouchEvent(MotionEvent ev) {
        Log.e("zhu", "view2 onTouchEvent");
        return super.onTouchEvent(ev);
    }

    @Override
    public boolean onInterceptTouchEvent(MotionEvent ev) {
        Log.e("zhu", "view2 onInterceptTouchEvent");
        return super.onInterceptTouchEvent(ev);
    }

    private class MyAdapter extends BaseAdapter{

        @Override
        public int getCount() {
            return 20;
        }

        @Override
        public Object getItem(int i) {
            return String.valueOf(i);
        }

        @Override
        public long getItemId(int i) {
            return 0;
        }

        @Override
        public View getView(int i, View view, ViewGroup viewGroup) {
            TextView tview  = new TextView(viewGroup.getContext());
            tview.setPadding(40, 40 ,40, 40);
            tview.setText("item "  + getItem(i));
            return tview;
        }
    }
}
